<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: track.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');


echo $this->lh;
if($this->track->access == 0 || $this->user->get('id') > 0)  {
    echo $this->map;
    ?>
    <script language="javascript" type="text/javascript">

    function submitbutton(pressbutton)
    {
            var form = document.adminForm;


        // do field validation
            if (document.getElementById('format').value == ""){
                    alert( "<?php echo JText::_( 'GPS_NEED_FORMAT', true ); ?>" );
        } else {
            submitform( pressbutton);
            }
    }


    function startGallery() {
            var myGallery = new gallery($('myGallery'), {
                    timed: true,
                    showArrows: true,
                    embedLinks: false,
                    showCarousel: false
            });
    }
    window.addEvent('domready',startGallery);

    </script>
    <script type="text/javascript">
    dojo.require("dojox.charting.Chart2D");
    dojo.require("dojox.charting.widget.Legend");

    makeCharts = function(){
        var hb = '<?php echo JText::_('GPS_HEARTFREQU'); ?>';
        var ele = '<?php echo JText::_('GPS_ELEVATION'); ?>';
        var chart1 = new dojox.charting.Chart2D("elevation");
        chart1.addPlot("default", {type: "Lines", hAxis: "x", vAxis: "y", markers: false, tension:4, shadows: {dx: 2, dy: 2, dw: 2}});
        chart1.addAxis("x", {leftBottom: true, majorLabels: false, minorLabels: true, majorTickStep: 100});
        chart1.addAxis("y", {vertical: true, fixUpper: "major", includeZero: false, majorTickStep: 200, fontColor:"#<?php echo $this->cfg->charts_linec; ?>"});
        chart1.addPlot("other", {type: "Lines", hAxis: "x", vAxis: "other y"});
        chart1.addAxis("other y", {vertical: true, leftBottom: false, fontColor:"#<?php echo $this->cfg->charts_bg; ?>"});
        chart1.addSeries(ele, [<?php echo $this->chart; ?>],
            {plot: "default", stroke: {color:"#<?php echo $this->cfg->charts_linec; ?>"}}
        );
        chart1.addSeries(hb, [<?php echo $this->beat; ?>],
            {plot:"other", stroke: {color:"#<?php echo $this->cfg->charts_bg; ?>"}}
        );
        chart1.render();
        var legend1 = new dojox.charting.widget.Legend({chart: chart1, horizontal: true}, "legend1");
        legend1.chart=chart1;
    };

    dojo.addOnLoad(makeCharts);
    </script>
    <div class="tracktitle"><?php echo $this->track->title; ?></div>
    <center><div id="map" style="width: <?php echo $this->cfg->map_width; ?>px; height: <?php echo $this->cfg->map_height; ?>px; margin-bottom:20px;" ></div>
    </center>
    <div id="profile">
        <div class="profile-img" id="elevation" style="width:<?php echo $this->cfg->charts_width; ?>px; height: <?php echo $this->cfg->charts_heigth; ?>px;"></div>
        <div id="legend1" style="width:200px; height:50px;"></div>
        <div class="gps-info">
            <table border="0" width="550px" align="center">
                <thead>
                    <tr>
                        <th colspan="3"><?php echo JText::_('GPS_DETAILS'); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><?php echo JText::_('GPS_FROM'); ?></td>
                        <td><?php echo $this->profile; ?></td>
                        <td rowspan="8" valign="top">
                            <div id="count-box">
                            <div align="center"><span><label for="speed"><?php echo JText::_('GPS_AVG_SPEED'); ?></label><input type="text" name="speed" id="speed" value="" size="4" /></span><input type="button" name="button" class="button" value="Submit" onclick="getAvgTime(document.getElementById('speed').value,<?php echo $this->distance; ?>);" /></div>
                            <div align="center"><span><label for="time"><?php echo JText::_('GPS_ESTIMATED_TIME'); ?></label><input type="text" name="time" id="time" value="" size="9" readonly="true" /></span></div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_DATE'); ?></td>
                        <td><?php echo $this->date; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_LEVEL'); ?></td>
                        <td valign="top"><?php echo $this->levelimg; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_DISTANCE'); ?></td>
                        <td><?php echo $this->distance. " " . $this->unit; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_ELEVATION'); ?> +</td>
                        <td><?php echo $this->track->ele_asc; ?> <?php echo JText::_('GPS_METERS'); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_ELEVATION'); ?> -</td>
                        <td><?php echo $this->track->ele_desc; ?> <?php echo JText::_('GPS_METERS'); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('HITS'); ?></td>
                        <td><?php echo $this->track->hits; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo JText::_('GPS_CAT'); ?></td>
                        <td><img src="<?php echo JURI::base(); ?>/images/joomgpstracks/cats/<?php echo $this->track->image; ?>" alt="<?php echo $this->track->cat; ?>" title="<?php echo $this->track->cat; ?>" height="32px" /></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="no-float">
        </div>
    </div>
    <div class="gps-headline"><?php echo JText::_('GPS_VOTING'); ?></div>
    <div class="description">
    <div id="ratingbox">
    <ul id="1001" class="rating <?php echo $this->vote['class']; ?>">
      <li id="1" class="rate one"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=1&id='.$this->track->id); ?>" title="1 Star">1</a></li>
      <li id="2" class="rate two"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=2&id='.$this->track->id); ?>" title="2 Stars">2</a></li>

      <li id="3" class="rate three"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=3&id='.$this->track->id); ?>" title="3 Stars">3</a></li>
      <li id="4" class="rate four"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=4&id='.$this->track->id); ?>" title="4 Stars">4</a></li>
      <li id="5" class="rate five"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=5&id='.$this->track->id); ?>" title="5 Stars">5</a></li>
      <li id="6" class="rate six"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=6&id='.$this->track->id); ?>" title="6 Stars">6</a></li>
      <li id="7" class="rate seven"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=7&id='.$this->track->id); ?>" title="7 Stars">7</a></li>
      <li id="8" class="rate eight"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=8&id='. $this->track->id); ?>" title="8 Stars">8</a></li>

      <li id="9" class="rate nine"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=9&id='.$this->track->id); ?>" title="9 Stars">9</a></li>
      <li id="10" class="rate ten"><a href="<?php echo JRoute::_('index.php?option=com_joomgpstracks&task=vote&rate=10&id='.$this->track->id); ?>" title="10 Stars">10</a></li>
    </ul>
    <div>(<?php echo JText::_('GPS_RATINGS'); ?>&nbsp;<?php echo $this->vote['count']; ?>)</div>
    </div>
    <div id="downloadbox">
        <form name="adminForm" id="adminForm" method="post" action="<?php echo $this->action; ?>">
            <div><b><?php echo JText::_('GPS_DOWNLOAD_FILE'); ?></b></div>
            <span><label for="format"><?php echo JText::_('GPS_FORMAT'); ?>&nbsp;</label>
            <select name="format" id="format">
                    <option value=""><?php echo JText::_('GPS_SELECT'); ?></option>
                    <option value="gpx">GPX</option>
                    <option value="kml">KML</option>
                    <option value="tcx">Garmin</option>
            </select>
            <button class="button" type="button" onclick="submitbutton('download')">
                    <?php echo JText::_('Download') ?>
            </button>
            </span>
        <?php
        echo JHTML::_( 'form.token' ) . "\n"; ?>
        <input type="hidden" name="option" value="com_joomgpstracks" />
        <input type="hidden" name="id" value="<?php echo $this->track->id; ?>" />
        <input type="hidden" name="task" value="" />
        </form>
    </div>
    <div class="no-float"></div>
    </div>
    <div class="gps-headline"><?php echo JText::_('GPS_TERRAIN'); ?></div>
    <div class="description"><?php echo $this->track->terrain; ?></div>
    <div class="gps-headline"><?php echo JText::_('GPS_DESCRIPTION'); ?></div>
    <div class="description"><?php echo $this->track->description; ?></div>
    <?php
    if($this->images):
    ?>
    <div class="gps-headline"><?php echo JText::_('GPS_GALLERY'); ?></div>
    <div class="galleryContent">
            <div id="myGallery">
                <?php
                foreach($this->images as $image)  {
                    // only needed if you test on a fucking windows system
                    // GNU/Linux rules!!!!!!!!!!!!!!!!!
                    if($image != 'Thumbs.db') {
                    ?>
                    <div class="imageElement">
                            <h3><?php echo $this->track->title; ?></h3>
                            <p></p>
                            <img src="<?php echo JURI::base(); ?>images/joomgpstracks/<?php echo md5($this->track->title).'/'.$image; ?>" class="full" heigth="345px" />

                    </div>
                    <?php
                    }
                }
                ?>
            </div>
    </div>
    <?php
    endif;
    ?>
    <div class="no-float"></div>
    <?php
    // adding the comments
    if($this->cfg->comments == 1) {
        ?>
        <div class="comments"><?php echo JText::_('GPS_COMMENTS'); ?></div>
        <?php
        if(!$this->comments)  {
            echo "<div>".JText::_('GPS_NO_COMMENTS')."</div>";
        } else {
            for($i=0, $n=count($this->comments); $i<$n; $i++) {
                $comment = $this->comments[$i];
                ?>
        <div class='comment'>
        <div class="comment-header"><div class="comment-title"><?php echo ($i+1).": ".$comment->title; ?></div><div class="date"><?php echo JHTML::_('date', $comment->date, JText::_('DATE_FORMAT_LC4'));; ?></div><div class="no-float"></div></div>
        <div class="comment-autor"><?php echo JHTML::_('email.cloak', $comment->email, true,$comment->user,true); ?></div>
        <div class="comment-text"><?php echo $comment->text; ?></div>
        <div class="no-float"></div>
        </div>
                <?php
            }
        }
        //
        if($this->cfg->comment_who == 0) {
            echo $this->model->addcomment($this->cfg);
        } elseif ($this->cfg->comment_who == 1 && $this->user->get('id')) {
            echo $this->model->addcomment($this->cfg);
        } else {
            echo JText::_('GPS_ADD_COMMENT_NOT_AUTH');
        }
    } elseif ($this->cfg->comments == 2) {
        require_once( JPATH_PLUGINS . DS . 'content' . DS . 'jom_comment_bot.php' );
        echo jomcomment($this->track->id, "com_joomgpstracks");
    }
} else {
 echo '<p class="error">'.JText::_('GPS_NOT_AUTH').'</p>';
}
echo $this->footer;
?>
